package main

import "fmt"

func main() {
	s := [3]int{1, 2, 3}
	a1 := s[:0]

	fmt.Printf("len=%d cap=%d \n", len(a1), cap(a1)) //len=0 cap=3
	b1 := s[:2]
	fmt.Printf("len=%d cap=%d \n", len(b1), cap(b1)) //len=2 cap=3,元素为index=0,index=1
	c1 := s[1:2:cap(s)]
	fmt.Printf("len=%d cap=%d \n", len(c1), cap(c1)) //len=1 cap=2,元素为index=1,容量=cap(s)-1 =3-1=2
	//s[i:j:k]:长度=j-i,容量=k-i

	//-------------------------------------------------

	m := make(map[string]int)
	m["a"] = 1
	//从map中获取不存在的值时，返回值类型对应的零值，所以返回 0 和 false。
	if v, ok := m["b"]; !ok {
		fmt.Println(v)
	}

	//-------------------------------------------------
	c := Work{3}
	var a A = c
	var b B = c
	fmt.Println(a.ShowB()) //编译错误，A中没有ShowB()方法
	fmt.Println(b.ShowA()) //编译错误，B中没有ShowA()方法
}

type A interface {
	ShowA() int
}

type B interface {
	ShowB() int
}

type Work struct {
	i int
}

func (w Work) ShowA() int {
	return w.i + 10
}

func (w Work) ShowB() int {
	return w.i + 20
}
